<template>
  <div class="big-box">
    <div class="top-box">
      <div class="left">
        <div class="in-box">
          <img class="jiao" src="@/assets/home/jiao.png" /><img class="img" src="@/assets/home/title.png" />已建项目
        </div>
      </div>
      <div class="right">
        <a-input allowClear v-model="keyword" style="width: 200px" placeholder="请输入搜索内容">
          <a-icon slot="prefix" type="search" style="color: #fff" />
        </a-input>
        <a-button type="primary" style="margin-left: 20px" @click="onSearch">查询</a-button>
        <div class="item"><img src="@/assets/home/file1.png" />新建项目</div>
        <div class="item"><img src="@/assets/home/file2.png" />打开项目</div>
        <div class="item"><img src="@/assets/home/file3.png" />我的项目</div>
      </div>
    </div>
    <div class="main-box">
      <div class="item" v-for="(item, index) in listData" :key="index">
        <img :src="item.stationImg ? item.stationImg : defaultImg" />
        <div class="title">{{ item.stationName }}</div>
        <div class="min-title">{{ item.createTime }}</div>
      </div>
    </div>
    <div class="footer">
      <a-pagination
        show-quick-jumper
        :page-size.sync="pageSize"
        :default-current="currentPage"
        :total="total"
        @change="onChange"
        @showSizeChange="onShowSizeChange"
        :showTotal="showTotal"
      />
    </div>
  </div>
</template>

<script>
import { getAllProject } from '@/api/record.js';
import defaultImg from '@/assets/home/main-bg.png';

export default {
  data() {
    return {
      listData: [],
      currentPage: 1,
      pageSize: 18,
      total: 0,
      defaultImg: defaultImg,
      keyword: ''
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      const params = {
        ps: this.pageSize,
        pn: this.currentPage,
        keyword: this.keyword
      };
      getAllProject(params).then(res => {
        this.total = res.data.total;
        this.listData = res.data.records;
      });
    },
    onShowSizeChange(current, size) {
      // 切换每页显示条数
      this.pageSize = size;
      this.getList();
    },
    onChange(page, pageSize) {
      // 切换页码
      this.currentPage = page;
      this.getList();
    },
    showTotal(total, range) {
      return '共' + total + '条';
    },
    onSearch() {
      this.currentPage = 1;
      this.getList();
    }
  }
};
</script>

<style scoped lang="scss">
.big-box {
  background-color: #021c2e;
  height: calc(100vh - 116px);
  max-height: calc(100vh - 116px);
  overflow: hidden;
  overflow-y: auto;
  .top-box {
    height: 48px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    .left {
      width: 316px;
      color: #fff;
      font-weight: 700;
      font-size: 20px;
      padding: 4px 8px;
      background: rgba(22, 102, 240, 0.2);
      margin-top: 8px;
      margin-bottom: 4px;
      border-radius: 4px;

      .in-box {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 40px;
        background: linear-gradient(90deg, rgba(22, 102, 240, 0.2) 0%, rgba(59, 150, 255, 0) 100%);
        padding-left: 16px;
        .jiao {
          position: absolute;
          left: -5px;
          top: -5px;
          width: 20px;
          height: 20px;
        }
        .img {
          width: 40px;
          height: 40px;
          position: absolute;
          left: 0;
          top: 0;
        }
      }
    }
    .right {
      display: flex;
      align-items: center;

      .item {
        width: 160px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        background: rgba(22, 102, 240, 0.2);
        color: #fff;
        font-size: 18px;
        margin-left: 32px;
        img {
          width: 24px;
          height: 24px;
          margin-right: 8px;
        }
      }
    }
    .right ::v-deep i {
      color: #fff;
    }
  }

  .main-box {
    width: 100%;
    display: flex;
    color: #fff;
    font-size: 18px;
    flex-wrap: wrap;
    .item {
      width: 290px;
      height: 235px;
      border-radius: 4px;
      background: rgba(22, 102, 240, 0.2);
      padding: 8px;
      margin-right: 22px;
      margin-bottom: 10px;
      img {
        width: 100%;
        height: 160px;
      }
      .title {
        margin: 6px 0;
      }
      .min-title {
        color: rgba(255, 255, 255, 0.6);
        font-size: 14px;
      }
    }
  }

  .footer {
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
  }
}
.footer ::v-deep .ant-pagination-item-ellipsis {
  color: #fff;
}
.big-box::-webkit-scrollbar {
  display: none; /*隐藏滚动条*/
}
</style>
